"""demo03_url URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, register_converter, re_path

from url_converter.converters import YearConverter

from url_app.views import *
from user.views import *
from url_converter.views import *
from re_app.views import *
from args_app.views import *

# 注册转换器
register_converter(YearConverter,'yy')
urlpatterns = [
    path('admin/', admin.site.urls),
    path('url/', test_url),
    path('url2/', test_url2),
    # -------------------------
    path('user/',get_user),
    path('user/info/', user_info),
    path('user/<id>', user_id),
    path('user/<int:id>/<gender>/', user_id_gender),    # 传递多个参数,注意因为有2个变量,所以2个/需要匹配,都有可能匹配到,所以尽量避免URL前缀一样
    path('user/by/<int:name>/', user_name),     # 传递一个参数
    path('user/path/<path:path>/', user_path),
    # --------------- 类型转换器 ---------------
    path('converter/<yy:year>/', test_converter),
    # --------------- 正则表达式 ---------------
    re_path(r'^(?P<year>[0-9]{4})/$', test_year),
    re_path('^re/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$', test_year_mon),
    # page-1 page-2
    re_path('^re/(?:page-(?P<num>\d+))/$', test_page_num),
    # --------------- 默认值 -------------------
    path('arg/', get_info),
    path('arg/<int:page>', get_info),
    # --------------- 额外参数值 ---------------
    path('other_arg/', other_age, {'info':'2030年'})
]

handler404 = 'error_app.views.page_not_found'